package labReport.experiment2;

class Bank {
    /*银行名称*/
    private String bankName = "支付宝";
    /*用户名*/
    private String username;
    /*密码*/
    private String password;
    /*账户余额*/
    private double balance;
    /*交易金额*/
    private double turnover;

    /*新用户开卡，构造方法传入用户名、密码、存入金额*/
    public Bank(String username, String password, double turnover) {
        this.username = username;
        this.password = password;
        this.turnover = turnover;
        this.balance = this.turnover - 10;
        System.out.println(username + " 开户成功，已扣除10元卡费，账户余额 " + balance + "元");
    }

    /*欢迎语，使用构造代码块*/ {
        System.out.println("——————花呗收钱生意好，支付就用" + bankName + "——————");
    }

    /*存钱*/
    void deposit(double turnover) {
        /*存钱金额需要大于0*/
        if (turnover > 0) {
            this.turnover = turnover;
            balance += this.turnover;
            System.out.println(username + "您好，您的账户已存入" + turnover + "元，当前余额" + balance + "元");
        } else {
            System.out.println("您操作的金额不符合要求");
        }
    }

    /*取钱*/
    void withdrawal(String password, double turnover) {
        /*需要同时满足密码正确，取钱金额大于0，取钱金额小于等于余额*/
        if (password == this.password && turnover > 0 && turnover <= this.balance) {
            this.turnover = turnover;
            balance -= this.turnover;
            System.out.println(username + "您好，您的账户已取出" + turnover + "元，当前余额" + balance + "元");
        } else if (password != this.password) {
            System.out.println("密码错误，取款失败!");
        } else if (turnover > this.balance) {
            System.out.println("您尝试取出" + turnover + "元，当前余额" + balance + "元，余额不足!");
        } else {
            System.out.println("您操作的金额不符合要求");
        }
    }

    /*用户退出*/
    void exit() {
        System.out.println("感谢您选择" + bankName);
    }
}

public class BankTest {
    public static void main(String[] args) {
        Bank card_1 = new Bank("法外狂魔张三", "123456", 99);
        card_1.deposit(199);
        card_1.withdrawal("234567", 666);
        card_1.withdrawal("123456", 666);
        card_1.withdrawal("123456", 222);
        card_1.exit();
    }
}
